package cn.wolfcode.luowowo.article.controller;

import cn.wolfcode.luowowo.article.domain.StrategyCommend;
import cn.wolfcode.luowowo.article.domain.StrategyDetail;
import cn.wolfcode.luowowo.article.service.IStrategyCommendService;
import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.common.query.StrategyCommendQueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/strategyCommend")
public class StrategyCommendController {
    @Reference
    private IStrategyCommendService strategyCommendService;
    @Reference
    private IStrategyDetailService strategyDetailService;
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") StrategyCommendQueryObject qo){
        //pageInfo
        PageInfo pageInfo = strategyCommendService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        List<StrategyDetail> details = strategyDetailService.listAll();
        model.addAttribute("details",details);
        return "strategyCommend/list";
    }
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        //根据id删除记录
        strategyCommendService.deleteById(id);
        return new AjaxResult();
    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCommend strategyCommend){
        //保存或者更新
        strategyCommendService.saveOrUpdate(strategyCommend);
        return new AjaxResult();
    }

}
